package projectOne.taoCan;

import projectOne.*;
import projectOne.service.CallService;
import projectOne.service.NetService;
import projectOne.service.SendService;

public class SuperPackage extends ServicePackage implements CallService, NetService, SendService {
    private int talkTime;//通话时长
    private int smsCount;//短信条数
    private int flow;//上网流量

    public SuperPackage() {
        super(78);
        this.talkTime=200;
        this.smsCount=50;
        this.flow=5*1024;
    }
    //发短信
    @Override
    public void send(int count, MobileCard card) {
        int temp=1;
        while (temp++<=count){
            if (smsCount-card.getRealSMSCount()>=1){
                card.setRealSMSCount(card.getRealSMSCount()+1);
            } else {
                card.setRealSMSCount(card.getRealSMSCount()+1);
                card.setMoney(card.getMoney()-0.1);
                card.setConsumAmount(card.getConsumAmount()+0.1);
            }
        }
    }
//打电话
    @Override
    public void call(int time, MobileCard card) {
        int temp=1;
        while (temp++<=time){
            if (talkTime-card.getRealTalkTime()>=1){
                card.setRealTalkTime(card.getRealTalkTime()+1);
            } else {
                card.setRealTalkTime(card.getRealTalkTime()+1);
                card.setMoney(card.getMoney()-0.2);
                card.setConsumAmount(card.getConsumAmount()+0.2);
            }
        }
    }

    @Override
    public void net(int flow, MobileCard card) {
        int temp=1;
        while (temp++<=flow){
            if (this.flow-card.getRealFlow()>=1){
                card.setRealFlow(card.getRealFlow()+1);
            } else {
                card.setRealFlow(card.getRealFlow()+1);
                card.setMoney(card.getMoney()-1);
                card.setConsumAmount(card.getConsumAmount()+1);
            }
        }
    }

    @Override
    public String toString() {
        return "通话时长："+talkTime+"\n短信条数："+smsCount+"\n流量："+flow/1024+"G"+"\n资费："+super.getPrice();
    }
}
